package com.xneure.utils.cns;

import java.util.ArrayList;
import java.util.List;

import com.xneure.utils.ObjectUtil;

public class NationalStandard {
	private String name;
	private String code;
	private List<NationalStandard> children;

	public NationalStandard(String name, String code) {
		this.name = name;
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public String getCode() {
		return code;
	}

	@SuppressWarnings("unchecked")
	public <T extends NationalStandard> List<T> getChildren() {
		return (List<T>) children;
	}

	public void add(NationalStandard dist) {
		if (null == children) {
			children = new ArrayList<NationalStandard>(10);
		}
		children.add(dist);
	}

	@SuppressWarnings("unchecked")
	public <T extends NationalStandard> T find(String nameOrCode) {
		if (code.equals(nameOrCode) || name.equals(nameOrCode)) {
			return (T) this;
		} else {
			if (ObjectUtil.isNotNull(children)) {
				NationalStandard findDistrict;
				for (NationalStandard dist : children) {
					findDistrict = dist.find(nameOrCode);
					if (null != findDistrict) {
						return (T) findDistrict;
					}
				}
			}
			return null;
		}
	}
}
